/**
 * Movie schedule item entity class
 */
package cult.ticketing.bean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Calendar;


/**
 * @author 51158282
 *
 */
public class ScheduleItem {
    //[movie_id], [house_id], [price], [show_time], [seating_plan]
    private int id; // ScheduleItem id
    private int movieId;
    private int houseId;
    private int price;
    private String showTime;
    private String bookedSeat;
    private String naSeat;


    /**
     *
     */
    public ScheduleItem() {
            // TODO Auto-generated constructor stub
    }

    public ScheduleItem(int id) {
            this.id = id;
    }

    public ScheduleItem(int id, int movieId, int houseId, int price, String showTime) {
        this.id = id;
        this.movieId = movieId;
        this.houseId = houseId;
        this.price = price;
        this.showTime = showTime;
    }

    public int getHouseId() {
        return houseId;
    }

    public void setHouseId(int houseId) {
        this.houseId = houseId;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getMovieId() {
        return movieId;
    }

    public void setMovieId(int movieId) {
        this.movieId = movieId;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getShowTime() {
        return showTime;
    }

    public void setShowTime(String showTime) {
        this.showTime = showTime;
    }

    public String getBookedSeat() {
        return bookedSeat;
    }

    public void setBookedSeat(String bookedSeat) {
        this.bookedSeat = bookedSeat;
    }

    public String getNaSeat() {
        return naSeat;
    }

    public void setNaSeat(String naSeat) {
        this.naSeat = naSeat;
    }



/*
	public static int getTotalScheduleItemCount() {
		int count = 0;
		
		// TODO retrieve data from db
		// count = select count id from schedule_item
		
		return count;
	}
	
	public static ScheduleItem[] getScheduleItem(int movieId) {
		// TODO retrieve schedule items of one movie from db
		// select * from scheduleItem where movie_id = movieId
		int itemCount = 0;
		// itemCount = rs.size
		ScheduleItem[] items = new ScheduleItem[itemCount];
		
		for (int i=0; i<itemCount; i++) {
			// TODO use constructor to initiate items[i]
			// items[i] = new ScheduleItem[rs.getInt("id"), etc]
			
		}
		
		return items;
			
	}

	public static ScheduleItem getScheduleItemById(int scheduleItemId) {
		ScheduleItem item = null;
		
		Connection con = DBConnector.getConnection();
		Statement stmt = null;
		ResultSet rs = null;
		
		try {
			// Create a statement
			stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
			rs = stmt.executeQuery("SELECT * FROM scheduleItem WHERE id = " + scheduleItemId);
			
			// TODO process the result and set ScheduleItem properties
			// item = new ScheduleItem(rs.getInt("id"), etc..);
						
		} catch(SQLException e) {
			System.out.println(e.toString());
		} finally {
			try {
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				if (con != null)
					con.close();
			} catch(Exception e) {
				System.out.println(e.toString());
			}
		}
		
		return item;
	}
*/

	
/*	public int[] getSeatAvailability(int[] index) {
		int indexSize = index.length;
		int[] seatAvailability = new int[indexSize];
		seatAvailability[0] = DEFAULT_SEAT_INDEX_VALUE;
		
		for (int i=0; i<indexSize-1; i++)
			if (index[i+1] < seatingPlan.length)
				seatAvailability[i+1] = seatingPlan[index[i+1]];
		return seatAvailability;
	}*/

/*
	public void setSeatingPlan(int[] seatingPlan) {
		Connection con = DBConnector.getConnection();
		Statement stmt = null;
		ResultSet rs = null;
		
		try {
			// Create a statement
			stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
			// TODO revise the statement
			rs = stmt.executeQuery("UPDATE seatingPlan:this.seatingPlan where itemId = id");
			
			// TODO process the result and set ScheduleItem properties
			// movie = ....
						
		} catch(SQLException e) {
			System.out.println(e.toString());
		} finally {
			try {
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				if (con != null)
					con.close();
			} catch(Exception e) {
				System.out.println(e.toString());
			}
		}
		
		this.seatingPlan = seatingPlan;
	}

	public boolean setSeatAvailability(int index, int value) {
		boolean ifUpdateSuccessful = false;
		if (value == -1 || value == 0 || value == 1) {
			if (index < seatingPlan.length)
			{
				seatingPlan[index] = value;
				setSeatingPlan(seatingPlan);
				ifUpdateSuccessful = true;
			}
			else
				System.out.println("Index out of range");
		} else {
			System.out.println("Invalid value");
		}
		return ifUpdateSuccessful;
			
	}
 * */

}
